package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Publish;
import com.tanhua.server.service.MovementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/movements")
public class MovementsController {
    @Autowired
    private MovementsService movementsService;

    /**
     * 圈子-推荐动态
     * GET /movements/recommend
     */
    @GetMapping("/recommend")
    public ResponseEntity recommendMovementList(@RequestParam(defaultValue = "1") int page,
                                                @RequestParam(defaultValue = "10") int pagesize) {
        return movementsService.recommendMovementList(page, pagesize);
    }
    @GetMapping
    public ResponseEntity friendsMovementList(@RequestParam(defaultValue = "1") int page,
                                              @RequestParam(defaultValue = "10") int pagesize) {
        return movementsService.friendsMovementList(page,pagesize);
    }
    /**
     * 圈子-发布动态
     * POST /movements
     */
    @PostMapping
    public ResponseEntity publish(Publish publish, String location, MultipartFile[] imageContent) throws IOException {
        publish.setLocationName(location);
        return movementsService.savePublish(publish, imageContent);
    }
    /*
    * GET/movements/all
    * */@GetMapping("/all")
    public ResponseEntity findAlbumMovementList(@RequestParam(defaultValue = "1") int page,
                                                                       @RequestParam(defaultValue = "10") int pagesize,
                                                                       @RequestParam(required = false) Long userId) {
        return movementsService.all(page,pagesize,userId);
    }
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String publishId){
        return movementsService.like(publishId);
    }

    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String publishId) {
        return movementsService.dislike(publishId);
    }

    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String publishId) {
        return movementsService.love(publishId);
    }

    @GetMapping("/{id}/unlove")
    public  ResponseEntity unlove(@PathVariable("id") String publishId) {
        return movementsService.unlove(publishId);
    }

    @GetMapping("/{publishId}")
    public ResponseEntity findOnePublish(@PathVariable("publishId") String publishId) {
        return movementsService.findOnePublish(publishId);
    }

    @GetMapping("/visitors")
    public ResponseEntity findVisitorsList() {
        return movementsService.findVisitorsList();
    }

}
